package com.chao.demo.annotate;

import java.lang.reflect.Method;

/**
 * @author: zc
 * @create: 2025-05-15 11:23
 * @Description: TODO
 **/
public class MyAnnotationHandler {

    // 自定义注解处理器
    public void handle() {
        // 通过反射的机制获取自定义注解
        Class<CustomizeAnnotation> customizeAnnotationClass = CustomizeAnnotation.class;
        // 获取所有的方法
        Method[] declaredMethods = customizeAnnotationClass.getDeclaredMethods();
        // 循环遍历
        for (Method method : declaredMethods) {
            boolean flag = method.isAnnotationPresent(MyAnnotation.class);
            if (flag) {
                // 找到注解在
                MyAnnotation myAnnotation = method.getAnnotation(MyAnnotation.class);
                String myName = myAnnotation.myName();
                int myAge = myAnnotation.myAge();
                System.out.println("我的名字 = " + myName + "\t我的年龄 = " + myAge + "岁");
            }
        }
    }
}
